<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" autoFlush="true"%>
<%@include file="/common/tags.jsp"%>
<%@ page import="java.util.*"%>

<%@ page
	import="cn.myapps.core.validate.repository.action.ValidateRepositoryHelper"%>
<ww:bean name="cn.myapps.core.dynaform.form.action.FormHelper" id="fh">
	<ww:param name="moduleid" value="#parameters.moduleid" />
</ww:bean>
<html><o:MultiLanguage>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href='<ww:url value="/resource/css/main.css" />' type="text/css">
<ww:bean name="cn.myapps.core.dynaform.view.action.ViewHelper"
	id="viewHelper">
	<ww:param name="moduleid" value="#parameters.moduleid" />
</ww:bean>
<link href="../css/dialog.css" rel="stylesheet" type="text/css" />
<script src="common/fck_dialog_common.js" type="text/javascript"></script>
<script src='<ww:url value="/dwr/engine.js"/>'></script>
<script src='<ww:url value="/dwr/util.js"/>'></script>
<script src='<ww:url value="/dwr/interface/FormHelper.js"/>'></script>
<script src='<ww:url value="/dwr/interface/Sequence.js"/>'></script>
<script language="JavaScript" src="dialog.js"></script>
<script language="JavaScript" src="script.js"></script>
<script language="JavaScript" src="sequence.js"></script>
<SCRIPT language="JavaScript">

var dialog	= window.parent ;
var oEditor = dialog.InnerDialogLoaded() ;

// Gets the document DOM
var oDOM = oEditor.FCK.EditorDocument ;

var oActiveEl = dialog.Selection.GetSelectedElement() ;


//初始值
function InitDocument(){
	var editMode;
	oEditor.FCKLanguageManager.TranslatePage(document) ;
	if ( oActiveEl && (oActiveEl.tagName == 'INPUT'))
	{
		//基本
		temp.name.value	= oActiveEl.name;
		//temp.texttype.value	= oActiveEl.texttype ;
		for(var i=0;i<temp.texttype.options.length;i++)
			if(temp.texttype.options[i].value==oActiveEl.texttype){
		    	temp.texttype.selectedIndex = i;
				break;
		}
		//temp.fieldtype.value	= oActiveEl.fieldtype;
		for(i=0;i<temp.fieldkeyevent.options.length;i++)
			if(temp.fieldkeyevent.options[i].value==oActiveEl.fieldkeyevent){
		    	temp.fieldkeyevent.selectedIndex = i;
				break;
		}
		//temp.fieldkeyevent.value	= oActiveEl.fieldkeyevent;
		for(i=0;i<temp.fieldtype.options.length;i++)
			if(temp.fieldtype.options[i].value==oActiveEl.fieldtype){
		    	temp.fieldtype.selectedIndex = i;
				if (temp.fieldtype.options[i].value == 'VALUE_TYPE_DATE') {
		    		document.all('selectdate').checked = oActiveEl.selectdate == "true";
				}
				break;
		}
		temp.bordertype.value = initBorderType(oActiveEl.bordertype);
		if(oActiveEl.authority!=null)
			temp.authority.checked = oActiveEl.authority=="true";
		if(oActiveEl.mobile!=null)
			temp.mobile.checked = oActiveEl.mobile=="true";
		if(oActiveEl.refreshonchanged!=null)
			temp.refreshonchanged.checked = oActiveEl.refreshonchanged == "true";
		if(oActiveEl.calculateonrefresh!=null)
			temp.calculateonrefresh.checked = oActiveEl.calculateonrefresh == "true";
		if(oActiveEl.discript!=null)
			temp.discript.value = oActiveEl.discript;
		
		//值脚本
		temp.valuescript.value=oActiveEl.valuescript ;
		editmode=oActiveEl.editmode;
		//var items=oActiveEl.processdescription;
		//parseRelStr(items);
		
		
		
		/*
		  
		var libstr=HTMLDencode(oControl.validateLibs);
		var lib=libstr.split(';');
		var validateLibs=document.getElementsByName('validateLibs');
	    
	    for(var i=0; i< lib.length; i++){
		    for(var j=0; j< validateLibs.length; j++){
		    	if(validateLibs[j].value==lib[i]){
		    		validateLibs[j].checked=true;
		    	}
	   		}
   		}*/
		
		//校验脚本
		if(oActiveEl.validaterule!=null)
			temp.validaterule.value = oActiveEl.validaterule;
		//隐藏脚本
		if(oActiveEl.hiddenscript!=null)
			temp.hiddenscript.value = oActiveEl.hiddenscript;
		//打印隐藏脚本
		if(oActiveEl.hiddenprintscript!=null)
			temp.hiddenprintscript.value = oActiveEl.hiddenprintscript;
		//只读脚本
		if(oActiveEl.readonlyscript!=null)
			temp.readonlyscript.value = oActiveEl.readonlyscript;
		
		if(oActiveEl.filtercondition!=null)
			temp.filtercondition.value = oActiveEl.filtercondition;		
	}
	else
		oActiveEl = null ;
	
	dialog.SetOkButton( true ) ;
	dialog.SetAutoSize( true ) ;
	SelectField( 'name' ) ;
	
	//ev_onTyepch();
	//initForm();
	//modeChange(editMode);
}

// 替换特殊字符
function HTMLEncode(text){
	text = text.replace(/&/g, "@amp;") ; 
	text = text.replace(/"/g, "@quot;") ;
	text = text.replace(/</g, "@lt;") ;
	text = text.replace(/>/g, "@gt;") ;
	text = text.replace(/'/g, "@#146;") ;
	text = text.replace(/\ /g,"@nbsp;");
	return text;
}
// 替换特殊字符
function HTMLDencode(text){
	var textold;
	do {
		textold = text;
		text = text.replace("@amp;","&") ;
		text = text.replace('@quot;','"') ;
		text = text.replace("@lt;","<") ;
		text = text.replace("@gt;",">") ;
		text = text.replace("@#146;","'") ;
		text = text.replace("@nbsp;"," ");
        }
        while(textold != text);
	return text;
}

// 选项卡点击事件(ok)
function cardClick(cardID){
	var obj;
	for (var i=1;i<7;i++){
		obj=document.all("card"+i);
		obj.style.backgroundColor="#3A6EA5";
		obj.style.color="#FFFFFF";
	}
	obj=document.all("card"+cardID);
	obj.style.backgroundColor="#FFFFFF";
	obj.style.color="#3A6EA5";
	
	for (var i=1;i<7;i++){
		obj=document.all("content"+i);
		obj.style.display="none";
	}
	obj=document.all("content"+cardID);
	obj.style.display="";
	resize();
}



function getBorderType(){
  var value= '';
  var bordertype = document.getElementsByName('bordertype');
  if(bordertype.length>0){
	  for(var i=0;i<bordertype.length;i++){
		  if(bordertype[i].checked){
		     value = bordertype[i].value;
		  }
	  }
  }
  return value;
}

function initBorderType(value){
  var bordertype = document.getElementsByName('bordertype');
  if(bordertype.length>0){
	  for(var i=0;i<bordertype.length;i++){
		  if(value == "true"){
		     bordertype[1].checked=true;
		  }else{
		     bordertype[0].checked=true;
		  }
	  }
  }
}

function Ok()
{
	oEditor.FCKUndo.SaveUndoStep() ;
	var className="cn.myapps.core.dynaform.form.ejb.InputField";
	var borderType=getBorderType();
	var id=getFieldId();
	var processDescription=HTMLEncode( createRelStr());
	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'INPUT', {
									classname: className,
									id: id,
									name: GetE('name').value,
									texttype: temp.texttype.options[temp.texttype.selectedIndex].value,
									fieldtype:temp.fieldtype.options[temp.fieldtype.selectedIndex].value,
									fieldkeyevent:temp.fieldkeyevent.options[temp.fieldkeyevent.selectedIndex].value,
									bordertype:borderType,
									discript:GetE('discript').value,
									validaterule:GetE('validaterule').value,
									valuescript:GetE('valuescript').value,
									hiddenscript:GetE('hiddenscript').value,
									hiddenprintscript:GetE('hiddenprintscript').value,
									readonlyscript:GetE('readonlyscript').value,
									refreshonchanged:GetE('refreshonchanged').value,
									calculateonrefresh:GetE('calculateonrefresh').value,
									mobile:GetE('mobile').value,
									authority:GetE('authority').value,
									numberpattern:GetE('numberpattern').value,
									processdescription:processDescription,
									filtercondition:GetE('filtercondition').value
									} 
								   ) ;	
	// when edit form
	/*
	SetAttribute( oActiveEl, 'name'	, GetE('name').value ) ;
	SetAttribute( oActiveEl, 'type'	, GetE('texttype').value ) ;
	SetAttribute( oActiveEl, 'fieldtype'	, GetE('fieldtype').value ) ;
	SetAttribute( oActiveEl, 'fieldkeyevent'	, GetE('fieldkeyevent').value ) ;
	SetAttribute( oActiveEl, 'bordertype'	, borderType ) ;
	SetAttribute( oActiveEl, 'discript'	, GetE('discript').value ) ;
	SetAttribute( oActiveEl, 'validaterule'	, GetE('validaterule').value ) ;
	SetAttribute( oActiveEl, 'hiddenscript'	, GetE('hiddenscript').value ) ;
	SetAttribute( oActiveEl, 'hiddenprintscript'	, GetE('hiddenprintscript').value ) ;
	SetAttribute( oActiveEl, 'readonlyscript'	, GetE('readonlyscript').value ) ;*/
	
	return true ;
}

function getInnerHTML() {
	var s = '<input className="cn.myapps.core.dynaform.form.ejb.InputField"';
	s += ' type="text" ';
	s += ' name="'+HTMLEncode(temp.name.value)+'"';
	s += ' id = "'+getFieldId()+'"';
	s += ' refreshOnChanged="'+HTMLEncode(temp.refreshOnChanged.checked+"")+'"';
	s += ' calculateOnRefresh="'+HTMLEncode(temp.calculateOnRefresh.checked+"")+'"';
	s += ' discript="'+HTMLEncode(temp.discript.value)+'"';
	s += ' valueScript="'+HTMLEncode(temp.valueScript.value)+'"';
	s += ' validateRule="'+HTMLEncode(temp.validateRule.value)+'"';
	s += ' hiddenScript="'+HTMLEncode(temp.hiddenScript.value)+'"';
	s += ' hiddenPrintScript="'+HTMLEncode(temp.hiddenPrintScript.value)+'"';
	s += ' readonlyScript="'+HTMLEncode(temp.readonlyScript.value)+'"';
	s += ' textType="'+HTMLEncode(temp.textType.options[temp.textType.selectedIndex].value)+'"';
	s += ' fieldkeyevent="'+HTMLEncode(temp.fieldkeyevent.options[temp.fieldkeyevent.selectedIndex].value)+'"';
	s += ' fieldtype="'+HTMLEncode(temp.fieldtype.options[temp.fieldtype.selectedIndex].value)+'"';
	s += ' numberPattern="'+HTMLEncode(temp.numberPattern.value)+'"';
    s += ' processDescription="'+HTMLEncode( createRelStr())+'"';  
	s += ' filtercondition="'+HTMLEncode(temp.filtercondition.value)+'"';  
	s += ' borderType="'+getBorderType()+'"';  
	s += ' authority="'+temp.authority.checked+'"'; 
	s += ' mobile="'+temp.mobile.checked+'"'; 
	var editMode=document.all("editMode");     
      for(var i=0;i<editMode.length;i++){
		   if(document.all("editMode")[i].checked){
		  	s += ' editMode="'+HTMLEncode( document.all("editMode")[i].value)+'"';
	      }
	    }
	var validateLibs=document.getElementsByName('validateLibs');
	var libs='';
	for(var i=0; i< validateLibs.length; i++){
   		if(validateLibs[i].checked){
   			libs+=validateLibs[i].value+";";
   		}
   	}
   	libs=libs.substring(0,libs.length-1);
	s += ' validateLibs="'+HTMLEncode(libs)+'"';   
	s += '>';
  return s;
}

//检查内容是否完成正确
function ev_check(){
   if(temp.name.value==''){
 	 alert("{*[page.name.notexist]*}");
	  return false;
   }
   return !checkStartChar(temp.name.value);
}

function checkStartChar(value){
	return IsDigit(value,"{*[page.name.startingit]*}");
}

function ev_onTyepch() {
	npTD.style.display = 'none';
	noneTD.style.display = 'none';
	npDiv.style.display = 'none';
    if (document.all('fieldtype').value == 'VALUE_TYPE_NUMBER'){
 		npTD.style.display = '';
 		npDiv.style.display = '';
 	} else {
 		noneTD.style.display = '';
 	}
 	resize();
}
</script>

</HEAD>

<BODY onload="InitDocument()">

<form name="temp">
		<table border="0" cellpadding="3" cellspacing="0">
			<tr align=center>
				<td class="card" onclick="cardClick(1)" id="card1">{*[Basic]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(2)" id="card2">{*[Value_Script]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(3)" id="card3">{*[Validate_Script]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(4)" id="card4">{*[Hidden_Script]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(5)" id="card5">{*[Hidden_Print_Script]*}</td>
				<td width=2></td>
				<td class="card" onclick="cardClick(6)" id="card6">{*[ReadOnly_Script]*}</td>
				<td width=2></td>
			</tr>
			<tr>
				<td valign="middle" colspan="12" bgcolor="#ffffff" align="center"
					width="100%">
				<table border=1 cellpadding=3 cellspacing=1 class="content" id="content1" width="100%">
					<tr>
						<td class="commFont commLabel">{*[Name]*}:</td>
						<td colspan="4"><input type="text" name="name"  onchange="checkStartChar(this.value);" size="20"></td>
					</tr>
					<tr>
						<td class="commFont commLabel">{*[Textbox_Type]*}:</td>
						<td colspan="2"><select onchange="ev_onTyepch()"
							name="fieldtype">
							<option value="VALUE_TYPE_VARCHAR">{*[Text]*}</option>
							<option value="VALUE_TYPE_NUMBER">{*[Number]*}</option>
						</select></td>
						<td class="commFont commLabel">{*[TextType]*}:</td>
						<td><select name="texttype">
							<option value="text">{*[Common]*}</option>
							<option value="password">{*[Password]*}</option>
							<option value="readonly">{*[Readonly]*}</option>
							<option value="hidden">{*[Hidden]*}</option>
						</select></td>
					</tr>
					
					<tr>
						<td class="commLabel commFont">{*[Focus_Key]*}:</td>
						<td colspan="2"><select name="fieldkeyevent">
							<option value="Tabkey">Tab</option>
							<option value="Enterkey">Enter</option>
						</select></td>
						<td class="commLabel commFont"><div id ='npDiv' style="display: none">{*[Format]*}:</div></td>
						<td id="npTD" style="display: none">{*[eg]*}:##.##<br>
						<input type="text" name="numberpattern" size="13"></td>
						<td id="noneTD" style="display: none"></td>
					</tr>
					<tr id="nbr">
						<td class="commLabel commFont" >{*[Border]*}:</td>
						<td colspan="4">
						    <input type="radio" name="bordertype" value="false" checked>{*[Show]*}{*[Border]*}&nbsp;
							<input type="radio" name="bordertype" value="true">{*[None]*}{*[Border]*}
						</td>
					</tr>
					<ww:bean name="cn.myapps.core.commoninfo.action.CommonInfoHelper"
						id="ch" />
					<tr>
						<td colspan="5" align="center">
							<input type=checkbox name="refreshonchanged" value="true">{*[Refresh]*}&nbsp;
							<input type=checkbox name="calculateonrefresh" value="true">{*[Recalculate]*}&nbsp;
							<input type="checkbox" name="mobile" checked />{*[Mobile]*}&nbsp;
							<input type="checkbox" name="authority" value="true" />{*[Authority]*}&nbsp;
						</td>
					</tr>
					<tr>
						<td class="commLabel commFont">{*[Description]*}:</td>
						<td colspan="4"><textarea name="discript" style="width:100%;" rows="4"></textarea></td>
					</tr>
				</table>
				<table border="1" cellpadding="3" cellspacing="1" class="content"
					id="content2">
					<%@include file="commondialog.jsp"%>
				</table>
				<table border="1" cellpadding="3" cellspacing="1" class="content"
					id="content3">
					<tr>
						<td width="25%">
						<table>
							<%
								String applicationid = request.getParameter("application");
							    ValidateRepositoryHelper vrhpler = new ValidateRepositoryHelper();
								Map map = vrhpler.get_validate(applicationid);
								for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
									Object id = (Object) iter.next();
									String name = (String) map.get(id);
							%><tr>
								<td><input type="checkbox" name="validateLibs"
									value="<%=(String)id %>" /><%=name%></td>
							</tr>
							<%
								}
							%>
						</table>
						</td>
						<td width="75%"><textarea name="validaterule" cols="40"
							rows="10"></textarea></td>
					</tr>
				</table>
				<table border="1" cellpadding="3" cellspacing="1" class="content" width="100%" id="content4">
					<tr>
						<td><textarea name="hiddenscript" style="width:100%" rows="10"></textarea></td>
					</tr>
				</table>
				<table border="1" cellpadding="3" cellspacing="1" class="content" width="100%"
					id="content5">
					<tr>
						<td><textarea name="hiddenprintscript" style="width:100%" rows="10"></textarea></td>
					</tr>
				</table>
				<table border="1" cellpadding="3" cellspacing="1" class="content" width="100%"
					id="content6">
					<tr>
						<td><textarea name="readonlyscript" style="width:100%" rows="10"></textarea></td>
					</tr>
				</table>
				</td>
			</tr>
		</table>
</form>

<script language=javascript>
cardClick(1);
</script>

</BODY>
</o:MultiLanguage>
</HTML>
